package com.mpgame.database.mysql.mapper.game;

import com.mpgame.database.mysql.mapper.BaseMapper;
import com.mpgame.database.mysql.model.game.Monster;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface MonsterMapper extends BaseMapper<Monster> {
    
    @Insert("INSERT INTO monster (name, family_id, melee_atk_base, magic_atk_base, melee_def_base, magic_def_base, speed_base, health_base, description) VALUES (#{name}, #{familyId}, #{meleeAtkBase}, #{magicAtkBase}, #{meleeDefBase}, #{magicDefBase}, #{speedBase}, #{healthBase}, #{description})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Monster monster);

    @Select("SELECT * FROM monster WHERE id = #{id}")
    Monster selectById(@Param("id") int id);

    @Select("SELECT * FROM monster WHERE name = #{name}")
    Monster selectByName(@Param("name") String name);

    @Select("SELECT * FROM monster WHERE family_id = #{familyId}")
    List<Monster> selectByFamilyId(@Param("familyId") int familyId);

    @Select("SELECT * FROM monster")
    List<Monster> selectAll();

    @Update("UPDATE monster SET name = #{name}, family_id = #{familyId}, melee_atk_base = #{meleeAtkBase}, magic_atk_base = #{magicAtkBase}, melee_def_base = #{meleeDefBase}, magic_def_base = #{magicDefBase}, speed_base = #{speedBase}, health_base = #{healthBase}, description = #{description} WHERE id = #{id}")
    int updateById(Monster monster);
}
